Java线程池之ScheduledExecutorService

Java线程池之ScheduledExecutorService

主要方法:

  public ScheduledFuture<?> schedule(Runnable command,long delay, TimeUnit unit)

  public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit);

  创建一个scheduledFuture,使得它在指定的时间延迟后执行。

  

 

  public ScheduledFuture<?> scheduleAtFixedRate(Runnable command,long initialDelay,long period,TimeUnit unit);

  创建一个action,在第一次延迟initDelay后,进行周期性的执行action。第一个action在创建后,延迟initDelay后进行执行,之后距离创建initDelay+period执行,之后是距离创建iniDelay+2*period执行。

  如果由于运行过程中出现exception,那么后续的将不会运行。

  如果这个任务的任何执行时间比其周期长,则后续执行可能起步较晚,但不会同时执行。

  

 

  public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay,long delay,TimeUnit unit)

  创建和执行周期性的action。在给定的delay时间执行action。此处的延迟是一个任务的停止到下一个任务的开始之间的延迟。

  当一个任务在执行过程中出现exception时,后续的执行将不会继续。  

 

 



 

  



 

 

posted @ 2016-04-05 10:41  youyouhuo  阅读(313)  评论(0编辑  收藏  举报